package com.setting.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Ope;
import com.entity.Sysdic;
import com.login.entity.JsonLogin;
import com.setting.entity.JsonSys;
import com.setting.service.OpeService;
import com.setting.service.SysdicService;
import com.utils.JsonResult;
import com.utils.JsonSysdic;

/**
 * @Title: OpeController.java
 * @Package com.setting.controller
 * @author 孙梦楠
 * @date 2017年11月4日 上午11:16:25
 * @version V1.0.0
 */
@RestController
@RequestMapping(value = "/setting/ope")
public class OpeController {

	@Autowired
	private OpeService opeService;

	@Autowired
	private SysdicService sysdicservice;

	// 组织架构列表
	@RequestMapping(value = "/listsysdicorg", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicorg(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0001";
		Integer state = 240;
		String Message = "组织架构字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message, languagecookie);
	}

	// 组织架构列表
	@RequestMapping(value = "/listsysdictype", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdictype(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0006";
		Integer state = 241;
		String Message = "用户类别字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message, languagecookie);
	}

	@RequestMapping(value = "/listsysdicmenu", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicmenu(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0030";
		Integer state = 242;
		String Message = "用户菜单权限字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message, languagecookie);
	}

	// 展示所有
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public JsonResult<List<JsonLogin>> listopes(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		return opeService.listopes(languagecookie);
	}

	// 新增
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JsonResult<Ope> addope(@RequestBody Ope ope) {

		String opecode = ope.getOpecode();
		String opename = ope.getOpename();
		Integer opeorg = ope.getOpeorg();
		String opeurl = ope.getOpeurl();
		String opetype = ope.getOpetype();
		String opemenu = ope.getOpemenu();
		String opephone = ope.getOpephone();

		return opeService.addope(opecode, opename, opeorg, opeurl, opetype, opemenu, opephone);
	}

	// 删除
	@RequestMapping(value = "/delect", method = RequestMethod.POST)
	public JsonResult<Ope> delect(@RequestBody Ope ope) {

		Integer opeid = ope.getOpeid();

		return opeService.delectope(opeid);
	}

	// 展示单个
	@RequestMapping(value = "/getbyid", method = RequestMethod.POST)
	public JsonResult<JsonLogin> updateviewope(@RequestBody Ope ope,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		Integer opeid = ope.getOpeid();

		return opeService.updateviewope(opeid, languagecookie);
	}

	// 修改
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public JsonResult<Ope> updateope(@RequestBody Ope ope) {

		Integer opeid = ope.getOpeid();
		String opecode = ope.getOpecode();
		String opename = ope.getOpename();
		Integer opeorg = ope.getOpeorg();
		String opeurl = ope.getOpeurl();
		String opetype = ope.getOpetype();
		String opemenu = ope.getOpemenu();
		String opephone = ope.getOpephone();

		return opeService.updateope(opeid, opecode, opename, opeorg, opeurl, opetype, opemenu, opephone);
	}

	// 修改密码 JsonLogin
	@RequestMapping(value = "/changepassword", method = RequestMethod.POST)
	public JsonResult<Ope> updatepassword(@RequestBody JsonLogin jsonLogin) {

		Integer opeid = jsonLogin.getOpeid();
		String opepassword = jsonLogin.getOpepassword();
		String newpassword = jsonLogin.getNewpassword();
		String newpassword2 = jsonLogin.getNewpassword2();

		return opeService.updatepassword(opeid, opepassword, newpassword, newpassword2);

	}

}
